﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;//添加命令空间，可以使用OleDbConnection等对象
using System.Data;//添加命令空间，可以使用dataset

public partial class adminstrator_addAdministrator : System.Web.UI.Page
{
    public OleDbConnection myConnection;
    public static readonly string sConnectionString = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sConnectionString);
        myConnection.Open();//打开数据库连接
        if (Session["UserName"] == null && Session["UserNo"] == null)//没有经过正常连接途径打开页面
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时（或未登录），请您重新登陆！');parent.location.herf='../login.aspx'</script>", false);

    }
    protected void ButtonOK_Click2(object sender, EventArgs e)
    {
        string manNo = nNo.Text.Trim();
        string manName = nName.Text.Trim();

        string manPass = nPass.Text.Trim();

        string mysql = "select * from ManagerTb  where nNo='" + manNo + "'";//查询学号
        OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);
        OleDbDataReader myReader = mycmd.ExecuteReader();//OleDbDataAdapter表示要对access数据源执行sql语句存储过程
        if (myReader.Read())
            nNo.Text = "输入的学号已经存在，请重新输入！";
        else
        {
            string myinsert = "insert into ManagerTb(nNo.nName.nPass) values" +
                "+(' " + manNo + "','" + manName + "','" + manPass + "'}";
            mycmd = new OleDbCommand(myinsert, myConnection);
            mycmd.ExecuteScalar();
            //弹出提示消息
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('学生信息添加成功！');</script>", false);//将所有输入框，列表框进行初始化
            nNo.Text = "";
            nName.Text = "";
            nPass.Text = "";
            LabelError.Text = "";
        }
    }
    protected void ButtonReset_Click(object sender, EventArgs e)
    {
        nNo.Text = "";
        nName.Text = "";
        nPass.Text = "";
        LabelError.Text = "";
    }

}